iterating over an STL collection
A set of data is represented in STL by a pair of
iterators. The first iterator references the first
element and the last iterator references one past
the last element. This is represented in half-open
interval notation as:
[first, last)
Iterating:
Instead of the typical C iteration:
for (i = 0; i < count; ++i)
{
arrayBase[i]; /* element */
}
In STL we use:
for (i = first; i != last; ++i)
{
(*i); // dereferenced object
}
Never dereference the "last" iterator. It can
only be used for comparing with the "first"
iterator.
(*last) is undefined.